package com.kcsoft.mapper;

import com.kcsoft.pojo.Message;
import com.kcsoft.pojo.Sessions;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.yaml.snakeyaml.events.Event;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MessageMapper {


    @Select("select * from dxai.session where create_user = #{id} and assistant_id = #{assistantId}")
    List<Sessions> findByUser(Integer id, String assistantId);

    @Insert("insert into dxai.message (question, create_time, session_id, answer, create_user) " +
            "values (#{question}, #{timestamp},#{sessionId}, #{answer}, #{id})")
    void saveMsg(String question, String sessionId, String answer, LocalDateTime timestamp, Integer id);

    @Select("select * from dxai.message where session_id = #{sessionId} order by create_time desc")
    List<Message> list(String sessionId);


    @Select("select * from dxai.message where question = #{question} and session_id = #{sessionId} and answer = #{answer} and create_time = #{createTime} and create_user=#{id}")
    Message hasMessage(String question, String sessionId, String answer, LocalDateTime createTime, Integer id);

    @Select("select * from dxai.message where create_user=#{id} order by create_time desc")
    List<Message> listAll(Integer id);

}
